<?php

namespace app\user\controller;

use app\common\service\FeedbackService;
use app\user\validate\FeedbackValidate;
use app\user\model\Feedback;
use app\common\attributes\RandyValidate;
use app\common\attributes\Menu;
use think\annotation\Inject;
use think\response\Json;
use think\App;

class FeedbackController extends UserBaseController
{

    protected Feedback $model;

    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->model = new Feedback();
    }

    #[Inject]
    protected FeedbackService $service;

    #[menu('查看用户反馈列表')]
    public function index() : Json
    {
        $data = $this->getParams();
        //当前是否为关联查询
        $this->relationSearch = true;
        //设置过滤方法
        $extendQueryHelper = $this->buildparams();
        $list = $this->service->getFeedbackList($extendQueryHelper, $data);
        foreach ($list as $row) {
        }
        return $this->success($list);
    }

    #[menu('查看用户反馈列表')]
    public function list()
    {
        $data = $this->getParams();
        //当前是否为关联查询
        $this->relationSearch = true;
        //设置过滤方法
        $extendQueryHelper = $this->buildparams();
        $extendQueryHelper->setIsPage(false);
        $list = $this->service->getFeedbackList($extendQueryHelper, $data);
        foreach ($list as $row) {
        }
        return $this->success($list);
    }


    #[menu('查看用户反馈详情')]
    #[RandyValidate(validate: FeedbackValidate::class, scene: 'read')]
    public function read($feedback_id) : Json
    {
        $res = $this->service->getFeedbackItem($feedback_id);
        return $this->returnSuccess($res);
    }

    #[menu('删除用户反馈')]
    #[RandyValidate(validate: FeedbackValidate::class, scene: 'del')]
    public function del($feedback_id) : Json
    {
        $res = $this->service->delFeedbackItem($feedback_id);
        return $this->returnSuccess($res);
    }

    #[menu('更新用户反馈')]
    #[RandyValidate(validate: FeedbackValidate::class, scene: 'update')]
    public function update($id) : \think\response\Json
    {
        $data = $this->getParams();
        $res = $this->service->setFeedbackItem($id, $data);
        return $this->returnSuccess();
    }

    #[menu('新增用户反馈')]
    #[RandyValidate(validate: FeedbackValidate::class, scene: 'save')]
    public function save() : Json
    {
        $data = $this->getParams();
        $data['user_id'] = get_client_id();
        $res = $this->service->addFeedbackItem($data);
        return $this->returnSuccess($res);
    }

    #[menu('设置反馈分类')]
    #[RandyValidate(validate: FeedbackValidate::class, scene: 'set_feedback_type')]
    public function setFeedbackType($feedback_id, $feedback_type) : Json
    {
        $res = $this->service->setFeedbackType($feedback_id, $feedback_type);
        return $this->returnSuccess($res);
    }

    #[menu('回复反馈')]
    #[RandyValidate(validate: FeedbackValidate::class, scene: 'reply')]
    public function reply($feedback_id, $reply_content) : Json
    {
        $res = $this->service->reply($feedback_id, $reply_content);
        return $this->returnSuccess($res);
    }
}
